package cn.dlike.LunarCalendar.controllers;

import com.jfinal.core.Controller;

import cn.dlike.LunarCalendar.beans.model.Birsthday;

public class Cp0000 extends Controller {
	
	public void index() {
		this.renderJsp("cp0000.jsp");
	}
	
	public void setBirthday() throws Exception {
		String name = this.getPara("name");
		Integer type = this.getParaToInt("type");
		String year = this.getPara("year");
		String months = this.getPara("months");
		String day = this.getPara("day");	
		String time = year+"年" + months + "月" + day +"日" ;
		
		Birsthday birthday = Birsthday.dao.findByName(name);
		
		if(birthday == null) {
			birthday =  Birsthday.dao.creatBirthday(name, type, time);
			System.out.println(birthday);
		}
		
//		Runnable runnable = new Runnable() {  
//			public void run() {  
//				// task to run goes here  
//				SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");		
//				Date nowTime = new Date();
//				String now = formatter.format(nowTime);
//				try {
//					now = CalendarUtil.solarToLunar(now);
//					System.out.println(now);
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//				List<TBirthday> tBirthday = TBirthday.dao.findByBirthDay(now);
//				for(int i = 0; i<tBirthday.size(); i++) {
//					System.out.println("今天是农历:"+now+",你的朋友："+tBirthday.get(i).getBName()+"今天生日");  
//				}
//			}  
//		};  
//		ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();  
//		// 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间  
//		service.scheduleAtFixedRate(runnable, 2, 5, TimeUnit.SECONDS);  
		
		this.renderJson();
	}
}
